<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>注册</title>
    <script src="https://www.layuicdn.com/auto/layui.js" v="2.5.6" e="layui"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/mobile/need/layer.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="static/js/jquerysession.js"></script>
    <link rel="stylesheet" href="static/css/login.css">
</head>

<body id="login">

<div class="login">
    <h2> <strong><font face="仿宋" >注册</font></strong></h2>
    <div class="layui-form-item">
        <input type="text" name="uname"  id="uname" placeholder="账号" class="layui-input" required>
        <i class="layui-icon input-icon">&#xe66f;</i>
    </div>

    <div class="layui-form-item">
        <input type="password" name="upwd" id="upwd" placeholder="密码"  class="layui-input" required>
        <i class="layui-icon input-icon">&#xe673;</i>
    </div>

    <div class="layui-form-item">
        <button type="button" style="width: 100%" class="layui-btn layui-btn-radius layui-btn-normal" lay-submit lay-filter="btn" id="btn">立即注册</button>
    </div>
    <p style="font-size: 0.8rem; margin-top: -0.3rem; text-align: right; color: red; position: absolute" id="adminLoginInfo"></p>

</div>



<script>
    layui.use(['layer', 'form'], function() {
        var layer = layui.layer;
        var form = layui.form;
        form.render('input')



//监听登录按钮
        $("#btn").click(function () {
            var uname = $("#uname").val();
            var upwd = $("#upwd").val();
            if (uname == '') {
                $("#adminLoginInfo").text("提示：账号不能为空！");
            } else if (upwd == '') {
                $("#adminLoginInfo").text("提示：密码不能为空！");
            } else{
                $.ajax({
                    type: "post",
                    url: "/user/adduser",
                    data: {
                        uname: uname,
                        upwd: upwd
                    },
                    dateType: "json",
                    success: function (data) {
                         if (data.trim() === "1") {
                            alert("注册成功")
                            window.location.href = "../index.html";
                        }
                    }
                })
            }
        })



    })

</script>
</body>

</html>
